<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      v-show="showSearch"
      :inline="true"
    >
      <el-form-item label="分类" prop="cate_id">
        <el-select
          v-model="queryParams.cate_id"
          placeholder="请选择产品"
          filterable
          clearable
           style="width: 150px"
        >
          <el-option
            v-for="cate in cateList"
            :key="cate.id"
            :label="cate.name"
            :value="cate.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="面值" prop="face_value">
        <el-input
          placeholder="面值"
          v-model="queryParams.face_value"
          clearable
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="产品" prop="spec_id">
        <el-select
          v-model="queryParams.spec_id"
          placeholder="请选择产品"
          filterable
          clearable
        >
          <el-option
            v-for="product in productList"
            :key="product.id"
            :label="product.cate?.name + product.face_value"
            :value="product.id"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="业务类型" prop="recharge_type">
        <el-select
          v-model="queryParams.recharge_type"
          placeholder="业务类型"
          clearable
          style="width: 100px"
        >
          <el-option label="话费" value="1" />
          <el-option label="流量" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="运营商" prop="isp">
        <el-select
          v-model="queryParams.isp"
          placeholder="运营商"
          clearable
          style="width: 100px"
        >
          <el-option label="移动" value="1" />
          <el-option label="联通" value="2" />
          <el-option label="电信" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="处理方式" prop="is_auto">
        <el-select
          v-model="queryParams.is_auto"
          placeholder="处理方式"
          clearable
          style="width: 100px"
        >
          <el-option
            v-for="dict in czType"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="order_status">
        <el-select
          v-model="queryParams.order_status"
          placeholder="状态"
          clearable
          style="width: 120px"
        >
          <el-option label="下单成功" value="1" />
          <el-option label="充值中" value="2" />
          <el-option label="充值完成" value="3" />
          <el-option label="充值失败" value="4" />
          <el-option label="压单" value="5" />
          <el-option label="失败拦截" value="6" />
        </el-select>
      </el-form-item>
      <el-form-item label="支付渠道" prop="payment_id">
        <el-select
          v-model="queryParams.payment_id"
          placeholder="支付渠道"
          clearable
          style="width: 120px"
        >
          <el-option
            v-for="item in payChannel"
            :key="item.id"
            :label="item.payment_name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态" prop="pay_status">
        <el-select
          v-model="queryParams.pay_status"
          placeholder="支付状态"
          clearable
          style="width: 120px"
        >
          <el-option label="已支付" value="1" />
          <el-option label="未支付" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="微信退款" prop="refund_status">
        <el-select
          v-model="queryParams.refund_status"
          placeholder="微信退款"
          clearable
          style="width: 120px"
        >
          <el-option label="未退款" value="0" />
          <el-option label="退款中" value="1" />
          <el-option label="退款成功" value="2" />
          <el-option label="退款失败" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="省份" prop="province_id">
        <el-select
          v-model="queryParams.province_id"
          placeholder="省份"
          clearable
          filterable
          @change="handleProvinceChange"
          @clear="handleProvinceClear"
          style="width: 120px"
        >
          <el-option
            v-for="province in provinceList"
            :key="province.id"
            :label="province.short_name"
            :value="province.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="城市" prop="city_id">
        <el-select
          v-model="queryParams.city_id"
          placeholder="城市"
          clearable
          filterable
          style="width: 120px"
        >
          <el-option
            v-for="city in cityList"
            :key="city.id"
            :label="city.short_name"
            :value="city.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="渠道" prop="channel_id">
        <el-select
          v-model="queryParams.channel_id"
          placeholder="请选择渠道"
          filterable
           style="width: 150px"
          clearable
        >
          <el-option
            v-for="channel in channelList"
            :key="channel.id"
            :label="channel.channel_name"
            :value="channel.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="平台订单号" prop="order_sn">
        <el-input
          v-model="queryParams.order_sn"
          placeholder="请输入平台订单号"
          clearable
          style="width: 260px"
        />
      </el-form-item>
      <el-form-item label="粉丝昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入"
          clearable
          style="width: 160px"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          style="width: 160px"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          ref="datePicker"
          v-model="dateRange"
          style="width: 380px"
          type="datetimerange"
          value-format="x"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="defaultTime"
        ></el-date-picker>
        <!-- value-format="yyyy/MM/dd HH:mm:ss" -->
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="Search"
          size="small"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" size="small" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <h3>订单操作只能针对商户自己的渠道,平台产品订单无法修改</h3>
    <h3>
      为了更好的统计订单利润，api提单的拿货价会自动根据渠道的成本价更新，手动处理的订单不影响
    </h3>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- v-hasPermi="['api:v1:updateCzChannel']" -->
        <el-button
          type="primary"
          plain
          icon="Download"
          size="small"
          @click="handleExport"
          v-hasPermi="['member:order:exportUserOrderList']"
          >导出</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="Edit"
          size="small"
          :disabled="multiple"
          @click="handleReSubmit"
          v-hasPermi="['member:order:orderReSubmit']"
          >重提订单</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Edit"
          size="small"
          :disabled="multiple"
          @click="handleProcessType(0)"
          v-hasPermi="['member:order:updateOrderProcessType']"
          >手动处理</el-button
        >
        <!-- v-hasPermi="['api:v1:updateOrderProcessType']" -->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          size="small"
          :disabled="multiple"
          @click="handleProcessType(1)"
          v-hasPermi="['member:order:updateOrderProcessType']"
          >自动处理</el-button
        >
        <!-- v-hasPermi="['api:v1:updateOrderProcessType']" -->
      </el-col>
      <!--
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['api:v1:cacheOrderSubmit']"
          @click="handleCacheSubmit"
          >压单重提</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['api:v1:stopFailOrderSubmit']"
          @click="handleStopFailSubmit"
          >拦截重提</el-button
        >
      </el-col>
      -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Edit"
          size="small"
          :disabled="multiple"
          v-hasPermi="['member:order:stopCzOrder']"
          @click="handleStop"
          >终止订单</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Edit"
          size="small"
          :disabled="multiple"
          @click="handleMutiStatus"
          v-hasPermi="['member:order:changeStatus']"
          >批量改状态</el-button
        >
      </el-col>
      <!-- // v-hasPermi="['api:v1:updateCzOrderStatus']" -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template #default="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <!-- <el-form-item label="用户是否支付" label-width="120px">
              <span v-if="props.row.pay_status == 1">已支付</span>
              <span v-if="props.row.pay_status == 0">未支付</span>
            </el-form-item> -->
            <el-form-item label="平台订单状态" label-width="120px">
              <span v-if="props.row.plat_status == 1">未扣款</span>
              <span v-if="props.row.plat_status == 2">已扣款</span>
              <span v-if="props.row.plat_status == 3">已退款</span>
            </el-form-item>
            <!-- <el-form-item label="超时时间">
              <span>{{ parseTime(props.row.timeout) }}</span>
            </el-form-item> -->
            <!-- <el-form-item label="商户拿货价">
              <span>{{ props.row.user_price }}</span>
            </el-form-item> -->
            <el-form-item label="凭证">
              <span>{{ props.row.voucher }}</span>
            </el-form-item>
            <el-form-item label="分佣" label-width="120px">
              <span>{{ props.row.commission?.name }}</span>
            </el-form-item>
            <el-form-item label="直/间推粉丝收益" label-width="120px">
              <span
                >{{ props.row.commission_money1 }}/{{
                  props.row.commission_money2
                }}</span
              >
            </el-form-item>
            <!-- <el-form-item label="成本">
              <span>{{ props.row.const_price }}</span>
            </el-form-item> -->

            <el-form-item label="备注">
              <span>{{ props.row.remark }}</span>
            </el-form-item>
            <el-form-item label="操作描述">
              <span>{{ props.row.act_remark }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="ID" align="center" prop="id" />

      <el-table-column label="订单号" align="center" prop="order_sn" />
      <el-table-column
        label="粉丝昵称"
        align="center"
        prop="mp_user.nickname"
      />
      <el-table-column label="粉丝ID" align="center" prop="mp_user.id" />
      <el-table-column label="产品" align="center" prop="product_name">
        <template #default="scope">
          <span>{{ scope.row.goods_full_title }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="售价" align="center" prop="sale_price" /> -->
      <el-table-column
        label="手机号"
        align="center"
        width="110"
        prop="mobile"
      />
      <el-table-column label="归属地/运营商" align="center" prop="isp">
        <template #default="scope">
          <span>{{ scope.row.area_name }}</span>
          <div v-if="scope.row.isp == 1">移动</div>
          <div v-if="scope.row.isp == 2">联通</div>
          <div v-if="scope.row.isp == 3">电信</div>
          <!-- <dict-tag :options="dict.type.cz_isp" :value="scope.row.isp" /> -->
        </template>
      </el-table-column>
      <el-table-column
        label="售价/拿货价/成本"
        align="center"
        prop="sale_price"
        width="280px"
      >
        <template #default="scope">
          <el-tag type="info">{{ scope.row.sale_price }}</el-tag
          >/ <el-tag type="warning">{{ scope.row.user_price }}</el-tag
          >/
          <el-tag type="success">{{ scope.row.const_price }}</el-tag>

          <!-- <dict-tag :options="dict.type.cz_isp" :value="scope.row.isp" /> -->
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="order_status">
        <template #default="scope">
          <el-tag v-if="scope.row.order_status == 1">下单成功</el-tag>
          <el-tag type="info" v-if="scope.row.order_status == 2">充值中</el-tag>
          <el-tag type="success" v-if="scope.row.order_status == 3"
            >充值成功</el-tag
          >
          <el-tag type="danger" v-if="scope.row.order_status == 4"
            >充值失败</el-tag
          >
          <el-tag type="warning" v-if="scope.row.order_status == 5"
            >压单</el-tag
          >
          <el-tag type="warning" v-if="scope.row.order_status == 6"
            >失败拦截</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column label="处理方式" align="center" prop="is_auto">
        <template #default="scope">
          <el-tag v-if="scope.row.is_auto == 1" type="success">自动</el-tag>
          <el-tag v-if="scope.row.is_auto == 0" type="warning">手动</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="is_auto">
        <template #default="{ row }">
          <el-tag v-if="row.pay_status == 1" type="success">已支付</el-tag>
          <el-tag v-else type="info">未支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="收款方式" align="center" prop="is_auto">
        <template #default="{ row }">
          <el-tag type="success">{{ row.pay?.payment_name || "无" }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="退款状态" align="center" prop="is_auto">
        <template #default="{ row }">
          <el-tag v-if="row.refund_status == 2" type="success">退款成功</el-tag>
          <el-tag v-if="row.refund_status == 3" type="danger">退款失败</el-tag>
          <el-tag v-if="row.refund_status == 1" type="info">退款中</el-tag>
          <el-tag v-if="row.refund_status == 0">未退款</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="分佣状态" align="center" prop="is_auto">
        <template #default="{ row }">
          <el-tag v-if="row.commission_status == 1" type="success"
            >已完成</el-tag
          >
          <el-tag v-else>未完成</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="业务" align="center" prop="recharge_type">
        <template #default="scope">
          <el-tag v-if="scope.row.recharge_type == 1">话费</el-tag>
          <el-tag v-if="scope.row.recharge_type == 2">流量</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        label="渠道"
        align="center"
        prop="channel.channel_name"
      />
      <el-table-column label="是否终止" align="center" prop="is_stop">
        <template #default="scope">
          <el-tag v-if="scope.row.is_stop == 1" type="success">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>
      <!-- 商户订单为非平台订单 -->
      <!-- <el-table-column label="平台订单" align="center" prop="is_member_order">
        <template #default="scope">
          <el-tag v-if="scope.row.is_member_order == 1" type="warning"
            >否</el-tag
          >
          <el-tag v-else type="success">是</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column
        label="创建/更新时间"
        align="center"
        prop="created_at"
        width="180"
      >
        <template #default="scope">
          <span>{{ scope.row.created_at }}</span>
          <br />
          <span>{{ scope.row.updated_at }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        prop="op"
        fixed="right"
        :show-overflow-tooltip="false"
      >
        <template #default="{ row }">
          <el-button
            v-if="
              (row.refund_status == 0 || row.refund_status == 3) &&
              row.pay_status == 1
            "
            type="primary"
            link
            icon="Position"
            @click="refund(row)"
            v-hasPermi="['member:order:refund']"
            >退款</el-button
          >
          <!-- <el-button type="primary"
link icon="Delete" @click="del(row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      title="批量改状态"
      v-model="open"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="已选择数量">
          {{ ids.length }}
        </el-form-item>
        <el-form-item label="温馨提示">
          <span style="color: red"
            >请确保没有勾选错订单以及要更改的订单状态!！！</span
          >
        </el-form-item>
        <el-form-item label="修改状态" prop="order_status">
          <el-radio-group v-model="form.order_status">
            <el-radio-button :label="2">充值中</el-radio-button>
            <el-radio-button :label="3">充值完成</el-radio-button>
            <el-radio-button :label="4">充值失败</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="密码"
          v-if="form.order_status == 4"
          prop="password"
        >
          <el-input
            v-model="form.password"
            placeholder="请输入登录密码确认操作"
            type="password"
            show-password
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入备注"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item
          label="是否回调"
          v-if="form.order_status == 3 || form.order_status == 4"
          prop="is_callback"
        >
          <el-radio-group v-model="form.is_callback" size="medium">
            <el-radio-button :label="0">不回调</el-radio-button>
            <el-radio-button :label="1">回调给客户</el-radio-button>
          </el-radio-group>
        </el-form-item> -->
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="loading2" type="primary" @click="submitForm"
            >确 定</el-button
          >
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog
      :title="title2"
      v-model="open2"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form ref="form2" :model="form2" :rules="rules2" label-width="100px">
        <el-form-item label="已选择数量">
          {{ ids.length }}
        </el-form-item>

        <el-form-item label="变更渠道" prop="change_channel">
          <el-radio-group v-model="form2.change_channel">
            <el-radio-button :label="0">不变更</el-radio-button>
            <el-radio-button :label="1">变更渠道</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="密码"
          v-if="form2.change_channel == 1"
          prop="password"
        >
          <el-input
            v-model="form2.password"
            placeholder="请输入登录密码确认操作"
            type="password"
            show-password
          />
        </el-form-item>
        <el-form-item label="温馨提示" v-if="form2.change_channel == 1">
          <span style="color: red"
            >请确认不要选错渠道，否则损失自负。请确认已提前添加好渠道产品，否则重提会失败。</span
          >
        </el-form-item>
        <el-form-item
          label="渠道"
          prop="channel_id"
          v-if="form2.change_channel == 1"
        >
          <el-select
            v-model="form2.channel_id"
            placeholder="请选择渠道"
            filterable
            clearable
          >
            <el-option
              v-for="channel in channelList"
              :key="channel.id"
              :label="channel.channel_name"
              :value="channel.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="loading2" type="primary" @click="submitForm2"
            >确 定</el-button
          >
          <el-button @click="cancel2">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <Dialog
      width="30%"
      :title="dialogConfig.title"
      v-model:isShowDialog="isShowDialog"
      :isLoading="isSubmitLoading"
      @confirm="submit"
    >
      <Form ref="formRef" v-bind="dialogConfig.formConfig"> </Form>
    </Dialog>
  </div>
</template>

<script>
// import {
//   getList as getUserCzOrderList,
//   changeStatus as updateCzOrderStatus,
//   orderReSubmit,
//   updateOrderProcessType,
// } from "@/api/platform/czOrder";
import {
  getList as getUserCzOrderList,
  refund,
  changeStatus as updateCzOrderStatus,
  updateOrderProcessType,
  orderReSubmit,
  stopCzOrder,
} from "@/api/member/order";

import { getMyAllList as listAllCzProduct } from "@/api/member/productSpec";
import {
  getAllList,
  getMyCateList as getAllCateList,
} from "@/api/member/productCate";
import { getArea as getAreas } from "@/api/common";

import { getAllChannel as listAllChannel } from "@/api/member/channel";
import { getPayAllList } from "@/api/member/paySet";
import { dialogConfig } from "./config";
export default {
  name: "merchantmerchantOrderindex",
  //   dicts: ["cz_product_type", "cz_order_status", "cz_isp"],
  data() {
    return {
      payChannel: [],
      cateList: [],
      dialogConfig,
      isShowDialog: false,
      isSubmitLoading: false,
      // 遮罩层
      loading: true,
      loading2: false,

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      dataList: [],
      customerList: [],
      productList: [],
      czType: [
        {
          label: "人工处理",
          value: 0,
        },
        {
          label: "自动处理",
          value: 1,
        },
      ],
      // 省份列表
      provinceList: [],
      channelList: [],

      // 省份列表
      cityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: this.getTimeFilterDefault(true),
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sys_user_id: undefined,
        spec_id: undefined,
        recharge_type: undefined,
        isp: undefined,
        order_status: undefined,
        province_id: undefined,
        city_id: undefined,
        face_value: undefined,
        order_sn: undefined,
        user_order_sn: undefined,
        mobile: undefined,
        channel_id: undefined,
        batch_order_sn: undefined,
        is_auto: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        order_status: [
          { required: true, message: "请选择状态", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      title2: "",
      open2: false,
      form2: {},
      rules2: {
        change_channel: [
          { required: true, message: "请选择是否变更渠道", trigger: "blur" },
        ],
        channel_id: [
          {
            required: true,
            message: "请选择渠道",
            trigger: "blur",
          },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      act: 0,
      open3: false,
      form3: {},
    };
  },
  created() {
    // this.getCustomerList();
    this.getProvinceList();
    // this.getAllProductList();
    this.getChannelList();
    this.getAllCateList();

    this.getList();
    this.getPayAllList();
  },
  computed: {
    defaultTime() {
      return [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)];
    },
  },
  methods: {
    async getPayAllList() {
      const { data } = await getPayAllList();
      this.payChannel = data;
    },
    async getAllCateList() {
      const { data } = await getAllCateList();
      this.cateList = data;
    },
    refund(item) {
      if (item) {
        // 点击退款按钮
        this.isShowDialog = true;
        this.dialogConfig.formConfig.formData = { ...item };
        // this.$modal
        //   .confirm("确定要退款吗？")
        //   .then(function () {
        //     return refund(item.id);
        //   })
        //   .then(() => {
        //     this.getInfo();
        //     this.$modal.msgSuccess("操作成功");
        //   })
        //   .catch(() => {});
      } else {
        // const ids = this.checkList.map((i) => i.id);
        // this.$modal
        //   .confirm("选中" + ids.length + "个,确定要批量退款吗？")
        //   .then(function () {
        //     return refund(ids);
        //   })
        //   .then(() => {
        //     this.getInfo();
        //     this.$modal.msgSuccess("操作成功");
        //   })
        //   .catch(() => {});
      }
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      const params = this.addDateRange(this.queryParams, this.dateRange);
      params.created_at = [params.params.beginTime, params.params.endTime];
      delete params.params;
      console.log(params);
      params.type = 1;
      getUserCzOrderList(params).then((response) => {
        const data = response.data;
        this.dataList = data.items;
        this.total = data.total;
        this.loading = false;
      });
    },
    getChannelList() {
      listAllChannel().then((response) => {
        this.channelList = response.data;
      });
    },
    getAllProductList() {
      listAllCzProduct().then((response) => {
        this.productList = response.data;
      });
    },
    // getCustomerList() {
    //   listAllCustomer().then((response) => {
    //     this.customerList = response.data;
    //   });
    // },
    getProvinceList() {
      // this.loading = true;
      getAreas({ level_type: 1 }).then((response) => {
        this.provinceList = response.data;
        // this.loading = false;
      });
    },
    getCityList(id) {
      getAreas({ level_type: 2, parent_id: id }).then((response) => {
        this.cityList = response.data;
      });
    },
    handleProvinceChange(val) {
      if (val) {
        this.getCityList(val);
      }
    },
    handleProvinceClear() {
      this.queryParams.city_id = undefined;
      this.cityList = [];
    },
    submitForm: function () {
      this.loading2 = true;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateCzOrderStatus({ ...this.form, ids: this.ids })
            .then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            })
            .finally(() => {
              this.loading2 = false;
            });
        } else {
          this.loading2 = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        order_status: undefined,
        is_callback: undefined,
        remark: undefined,
        password: undefined,
      };
      this.resetForm("form");
    },
    handleMutiStatus() {
      this.reset();
      this.open = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = this.getTimeFilterDefault(true);
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**订单回调*/
    handleCallback() {
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要回调所选的订单吗？")
        .then(function () {
          return czOrderCallback(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 终止订单操作 */
    handleStop(row) {
      const order_ids = row.id || this.ids;
      this.$modal
        .confirm(
          "是否要终止ID为[" +
            order_ids +
            "]的订单数据项？终止之后将不会拦截订单，将直接失败退款【仅对充值中的订单有效】"
        )
        .then(function () {
          return stopCzOrder(order_ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("终止成功，请耐心等待渠道回调。");
        })
        .catch(() => {});
    },
    //拦截重提
    handleStopFailSubmit() {
      this.reset2();
      this.title2 = "拦截重提";
      this.open2 = true;
      this.act = 2;
      return;
      /*
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要重新提交失败拦截的订单吗？")
        .then(function () {
          return stopFailOrderSubmit(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
      */
    },
    /** 导出按钮操作 */
    handleExport() {
      // 导出勾选的订单
      const orderIds = this.ids || [];
      console.log(orderIds);
      if (orderIds.length) {
        this.download(
          "member/order/exportUserOrderList",
          { ids: orderIds, type: "merchant" },
          "客户订单导出[" + this.parseTime(new Date().getTime()) + "].csv"
        );
      } else {
        const obj = this.addDateRange(this.queryParams, this.dateRange);
        obj.created_at = [obj.params.beginTime, obj.params.endTime];
        delete obj.params;
        obj.type = "merchant";
        this.download(
          "member/order/exportUserOrderList",
          obj,
          "客户订单导出[" + this.parseTime(new Date().getTime()) + "].csv"
        );
      }
    },
    submit() {
      this.$refs.formRef.validate(async (valid) => {
        if (valid) {
          this.isSubmitLoading = true;
          try {
            await refund(this.dialogConfig.formConfig.formData);
            this.$message.success("操作成功");
            this.isShowDialog = false;
            this.getInfo();
          } finally {
            this.isSubmitLoading = false;
          }
        }
      });
    },
    //压单重提
    handleCacheSubmit() {
      this.reset2();
      this.title2 = "压单重提";
      this.open2 = true;
      this.act = 1;
      return;
      /*
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要重新提交压单缓存订单吗？")
        .then(function () {
          return cacheOrderSubmit(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
        */
    },
    handleReSubmit() {
      this.reset2();
      this.title2 = "重提订单";
      this.open2 = true;
      return;
    },
    // 处理方式改变
    handleProcessType(type) {
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm(
          "确认要改变处理方式为：[" +
            (type == 1 ? "自动" : "手动") +
            "处理] 吗？"
        )
        .then(function () {
          return updateOrderProcessType({ ids, type });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
    },
    handleSelectionChange2(selection) {
      this.multipleSelection2 = selection;
      this.ids2 = selection.map((item) => item.id);
      this.single2 = selection.length != 1;
      // this.multiple2 = !selection.length;
    },
    cancel2() {
      this.open2 = false;
      this.reset2();
    },
    reset2() {
      this.act = 0;
      this.form2 = {
        change_channel: undefined,
        password: undefined,
        channel_id: undefined,
      };
      this.resetForm("form2");
    },
    //压单重提
    submitForm2() {
      this.loading2 = true;
      const ids = this.ids;
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          orderReSubmit({ ...this.form2, ids })
            .then((res) => {
              this.getList();
              this.$modal.msgSuccess("操作成功");
              this.open2 = false;
            })
            .finally(() => {
              this.loading2 = false;
            });
        } else {
          this.loading2 = false;
        }
      });
    },
  },
};
</script>
<style>
.demo-table-expand {
  padding: 0 10px;
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 33.3%;
}
</style>
